﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartHotel.BLL;
using SmartHotel.DAL;
using SmartHotel.Model;

namespace SmartHotel.WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {

        private readonly ILogger<OrderController> _logger;//使用_looger来操作日志
        public OrderController(OrderBLL orderBLL, ILogger<OrderController> logger = null)
        {
            OrderBLL = orderBLL;
            _logger = logger;
        }

        public OrderBLL OrderBLL { get; }

        [HttpPost]
        public int AddOrder(OrderModel order)
        {
            _logger.LogInformation("房间名称:"+order.RoomName+";房间数量:"+order.RoomCount);
            return OrderBLL.AddOrder(order);
        }
        [HttpGet]
        public MyPage<OrderModel> GetOrders(int index, int size,  string? username)
        {
            _logger.LogInformation("订单当前页:" + index + ";页容量:" + index + ";用户名称:" + username);
            int count = 0;
            var data = OrderBLL.GetOrders(index, size, out count, username);
            return data;
        }
        [HttpGet]
        public OrderModel GetOrderId(int id)
        {
            return OrderBLL.GetOrderId(id);
        }
        [HttpPut]
        public int LjDel(int id)
        {
            return OrderBLL.LjDel(id);
        }
        [HttpPut]
        public int ZhiFu(int id)
        {
            _logger.LogInformation("支付订单id:" + id);
            return OrderBLL.ZhiFu(id);
        }
    }
}
